Skip to content

移除 /cwd slash 命令,精简运行时工作目录切换逻辑#224

Merged
phantom5099 merged 6 commits into
1024XEngineer:mainfrom
wynxing:new_feat_workspace
Apr 11, 2026
Merged

移除 /cwd slash 命令,精简运行时工作目录切换逻辑#224
phantom5099 merged 6 commits into
1024XEngineer:mainfrom
wynxing:new_feat_workspace

Conversation

@wynxing

@wynxing wynxing commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • 删除 /cwd slash 命令及其在 TUI、runtime、gateway 三层的全部实现与引用,共涉及 20 个文件
  • 保留 CLI --workdir 启动参数指定工作目录的完整链路不受影响
  • 保留 runtime 内部 loadOrCreateSessionresolveWorkdirForSession 等辅助函数(供会话创建和 Run 流程继续使用)

变更范围

删除的文件:

  • internal/tui/core/commands/workspace.go/cwd 命令执行逻辑与 SessionWorkdirSetter 接口
  • internal/tui/core/commands/workspace_test.go — 对应测试

接口裁剪:

  • runtime.Runtime 接口移除 SetSessionWorkdir 方法
  • gateway.RuntimePort 接口移除 SetSessionWorkdir 方法
  • gateway.FrameActionSetSessionWorkdir 帧动作常量移除

TUI 层清理:

  • 移除 /cwd 命令注册、输入解析分支、结果消息类型及所有桥接函数
  • workspace/resolver.go 仅移除 ResolveWorkspacePath(仅 /cwd 使用),保留 SelectSessionWorkdir

测试同步更新:

  • 删除 4 个 runtime 层 SetSessionWorkdir 测试函数
  • 删除 gateway 校验测试中 set_session_workdir 用例
  • 更新 4 个测试 stub 移除 SetSessionWorkdir 实现
  • 重写 TestRunSlashCommandSelectionWorkspaceAndLocal 为 `TestRunSlashCommandSelectionLocalCommand

@codecov

codecov Bot commented Apr 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/session/workspace.go 88.88% 1 Missing and 1 partial ⚠️
internal/tui/core/app/update.go 80.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

@wynxing

wynxing commented Apr 11, 2026

Copy link
Copy Markdown
Collaborator Author

/review

fennoai[bot]

This comment was marked as outdated.

@wynxing

wynxing commented Apr 11, 2026

Copy link
Copy Markdown
Collaborator Author

/simplify

@fennoai

fennoai Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Result

已完成并推送到当前 PR 分支,提交为 313ac9d

本次处理了两类值得修复的问题:

  • 修复已有会话在重启后无法跟随新的启动 workdir 的回归。现在 TUI 会把当前界面工作目录持续作为 run 覆盖值传给 runtime,旧会话重新加载后也会回到启动工作目录语义。
  • 同步更新文档与实现细节:session.Workdir 的描述已改成“最近一次运行实际使用的目录”,配置文档补充了 workdir 必须存在且为目录的约束。

顺手做的简化:

  • 删除只剩透传作用的 internal/tui/core/workspace/resolver.go
  • config.Validate() 复用 session.ResolveExistingDir(),减少重复目录校验逻辑
  • 补了 TUI 定向测试,覆盖 run context 工作目录更新和旧会话重新加载后的工作目录行为

验证:go test ./... 通过。

未处理:没有恢复 gatewayset_session_workdir 兼容层。这里我判断不值得在这个 PR 里保留,因为该 PR 的目标就是移除运行期工作目录切换能力,而仓库内已经没有剩余消费者;继续保留只会留下一个表面可用、实际已废弃的协议入口。

fork 侧同步 PR 已创建:wynxing#2

View job run

xgopilot and others added 2 commits April 11, 2026 01:30
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
fix: rebind session workdir to startup workspace
@phantom5099

Copy link
Copy Markdown
Collaborator

/review -codex

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

发现 1 个值得修正的问题,主要是会话重新打开后的工作目录语义回归。

Comment thread internal/tui/core/app/update.go Outdated
a.clearActivities()
a.state.ActiveSessionTitle = session.Title
a.state.CurrentWorkdir = tuiworkspace.SelectSessionWorkdir(session.Workdir, a.configManager.Get().Workdir)
a.setCurrentWorkdir(a.configManager.Get().Workdir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里把 CurrentWorkdir 重置成了全局 config.Workdir,而不是刚加载出来的 session.Workdir。这会让已持久化了非默认工作目录的会话在重新打开后立刻丢失原来的目录语义;再结合本 PR 中 RequestedWorkdirForRun() 现在始终把 UI 当前目录作为显式覆盖值传回 runtime,下一次运行还会把这个全局目录写回会话,等于静默覆盖掉之前保存的 session.Workdir。结果是 UI 展示、& 本地命令/文件候选,以及后续 agent/tool 执行目录都会偏离该会话上次实际运行的目录,也和 docs/session-persistence-design.md 里对 session.Workdir 的描述不一致。

@wynxing

wynxing commented Apr 11, 2026

Copy link
Copy Markdown
Collaborator Author

/simplify

@fennoai

fennoai Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

结果

已处理并推送到当前 PR 分支,提交为 4bb3bef

本次先检查了历史评论,确认前面的大部分 review 点已经处理,只剩一个仍未解决的回归值得修:refreshMessages() 在重新打开已有会话时,会把 CurrentWorkdir 直接重置为全局 config.Workdir。这会丢失持久化的 session.Workdir,并让后续运行把错误目录继续写回会话。

已修复的内容:

  • internal/tui/core/app/update.go 现在会优先用 session.Workdir 恢复当前会话目录,仅在会话未记录目录时才回退到全局 config.Workdir
  • internal/tui/core/app/update_test.go 增加两条回归测试,分别覆盖“优先恢复会话目录”和“缺失时回退全局目录”

简化复查:按要求调用了 code-simplifier 子代理复查这块实现,结论是当前改动已经基本是最小形态,没有值得继续收敛的实现点;仅有一个可选的表驱动测试重构,但收益很小,未再变更。

验证:go test ./...

fork 侧同步 PR:wynxing#3

View job run

xgopilot and others added 2 commits April 11, 2026 06:22
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
fix: preserve session workdir on reload
@phantom5099 phantom5099 merged commit 496d350 into 1024XEngineer:main Apr 11, 2026
2 checks passed
@wynxing wynxing deleted the new_feat_workspace branch April 12, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants